#ifndef GLDRAWER_H
#define GLDRAWER_H

#include <QGLWidget>

#include <osgViewer/Viewer>

#include "EventHandler.h"
#include "CameraController.h"

class AdapterWidget : public QGLWidget
{
public:
	AdapterWidget(QWidget *parent = 0);
	virtual ~AdapterWidget() {}

	osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); }
	const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); }

protected:
    virtual void resizeGL(int width, int height);
    virtual void keyPressEvent(QKeyEvent* event);
    virtual void keyReleaseEvent(QKeyEvent* event);
    virtual void mousePressEvent(QMouseEvent* event);
    virtual void mouseReleaseEvent(QMouseEvent* event);
    virtual void mouseMoveEvent(QMouseEvent* event);
    virtual void wheelEvent(QWheelEvent *event);

    osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw;
};

class GLDrawer : public osgViewer::Viewer, public AdapterWidget
{
public:
    enum ViewMode {Top, Down, Front, Back, Left, Right, Perspective, Isometric};

public:
    GLDrawer(QWidget *parent);

	void setViewMode(ViewMode mode);
	ViewMode  getViewMode() { return viewMode; }
	CameraController* getCameraController() { return cameraController.get(); }

protected:
    void paintGL();

private:
    ViewMode viewMode;
	osg::ref_ptr<CameraController> cameraController;
};

#endif // GLDRAWER_H
